<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body onclick="alert('我是body')">
    <div onclick="parentFn()">
        parent
        <div onclick="childfn()">children</div>
    </div>
    <script>
        function childfn(){
            alert('children')
            // 阻止事件冒泡
            var event=window.event||arguments[0]
            
            
            if(event.stopPropagation){
                event.stopPropagation();//现代浏览器阻止冒泡
            }else{
                event.cancelBubble=true;//ie
            }
        }

        function parentFn(){
            alert('parentFn')
            event.stopPropagation();//现代浏览器阻止冒泡
        }
    </script>
</body>
</html>